package com.story.modular.app.controller;


import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Result;

import com.baomidou.mybatisplus.plugins.Page;
import com.story.common.persistence.model.Record;
import com.story.common.persistence.model.VedioCategory;
import com.story.core.base.controller.BaseController;
import com.story.modular.app.service.IRecordService;
import com.story.modular.app.warpper.VedioWarpper;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 /**
 * @Description: record
 * @Author: jeecg-boot
 * @Date:   2020-06-03
 * @Version: V1.0
 */
@Api(tags="record",value = "点击量，播放记录，订阅，下载接口")
@RestController
@RequestMapping("/api/record")
@Slf4j
public class RecordController extends BaseController {
	@Autowired
	private IRecordService recordService;
	
	/**
	 * 分页列表查询
	 *
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@ApiOperation(value="record-分页列表查询", notes="record-分页列表查询")
	@GetMapping(value = "/list")
	public Object queryPageList(@ApiParam(name="user", value="用户账号")  @RequestParam(required=false) String user,
								   @ApiParam(name = "type",value = "0音频记录1视频记录2专辑") @RequestParam(required=false)  Integer type,
								   @ApiParam(name = "jilutype",value = "记录类型 0播放记录1我的订阅2我的下载3点击量") @RequestParam(required=false)  Integer jilutype,
								   @ApiParam(name = "jiluid",value = "记录id 也就是视频 或者音频id 专辑Id") @RequestParam(required=false)  Integer jiluid,
								   @RequestParam(name="pageNo", defaultValue="1") @ApiParam(name = "pageNo",value = "第几页") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") @ApiParam(name = "pageSize",value = "一页几条")  Integer pageSize) {

		Record record=new Record();
		record.setAccount(user);
		record.setType(type);
		record.setJilutype(jilutype);
		record.setJiluid(jiluid);

		Page<Record> page = new Page<Record>(pageNo, pageSize);
		List<Record> list=recordService.selectPageList(page,record);
		page.setRecords(list);

		return page;
	}
	
	/**
	 *   添加
	 *
	 * @param record
	 * @return
	 */
	@ApiOperation(value="添加记录", notes="record-添加添加记录")
	@PostMapping(value = "/add")
	public Object add(@RequestBody Record record) {
		record.setCreatetime(new Date());
		recordService.insert(record);
		return super.SUCCESS_TIP;
	}
	
//	/**
//	 *  编辑
//	 *
//	 * @param record
//	 * @return
//	 */
//	@ApiOperation(value="record-编辑", notes="record-编辑")
//	@PutMapping(value = "/edit")
//	public Object edit(@RequestBody Record record) {
//		recordService.updateById(record);
//		return super.SUCCESS_TIP;
//	}
	
//	/**
//	 *   通过id删除
//	 *
//	 * @param id
//	 * @return
//	 */
//	@ApiOperation(value="record-通过id删除", notes="record-通过id删除")
//	@DeleteMapping(value = "/delete")
//	public Object delete(@RequestParam(name="id",required=true) String id) {
//		recordService.deleteById(id);
//		return super.SUCCESS_TIP;
//	}
	

	
//	/**
//	 * 通过id查询
//	 *
//	 * @param id
//	 * @return
//	 */
//	@ApiOperation(value="record-通过id查询", notes="record-通过id查询")
//	@GetMapping(value = "/queryById")
//	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
//		Record record = recordService.getById(id);
//		if(record==null) {
//			return Result.error("未找到对应数据");
//		}
//		return Result.ok(record);
//	}

//    /**
//    * 导出excel
//    *
//    * @param request
//    * @param record
//    */
//    @RequestMapping(value = "/exportXls")
//    public ModelAndView exportXls(HttpServletRequest request, Record record) {
//        return super.exportXls(request, record, Record.class, "record");
//    }

//    /**
//      * 通过excel导入数据
//    *
//    * @param request
//    * @param response
//    * @return
//    */
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//        return super.importExcel(request, response, Record.class);
//    }

}
